<?php
    /**
     * Created by PhpStorm.
     * User: jackhhy
     * Date: 2019/7/19-15:44
     * Link: https://gitee.com/luckygyl/LuckyAdmin
     * FileName: Article.php
     * Keys: ctrl+alt+L/ctrl+s(代码格式化) ctrl+J(代码提示) ctrl+R(替换)ALT+INSERT(生成代码(如GET,SET方法,构造函数等) , 光标在类中才生效)
     * CTRL+ALT+O (优化导入的类和包 需要配置) SHIFT+F2(高亮错误或警告快速定位错误)
     * CTRL+SHIFT+Z(代码向前) CTRL+SHIFT+/ (块状注释) ctrl+shift+enter(智能完善代码 如if())
     *
     **************************************************************
     *                                                            *
     *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.       *
     *    |                     ______                     |      *
     *    |                  .-"      "-.                  |      *
     *    |                 /            \                 |      *
     *    |     _          |              |          _     |      *
     *    |    ( \         |,  .-.  .-.  ,|         / )    |      *
     *    |     > "=._     | )(__/  \__)( |     _.=" <     |      *
     *    |    (_/"=._"=._ |/     /\     \| _.="_.="\_)    |      *
     *    |           "=._"(_     ^^     _)"_.="           |      *
     *    |               "=\__|IIIIII|__/="               |      *
     *    |              _.="| \IIIIII/ |"=._              |      *
     *    |    _     _.="_.="\          /"=._"=._     _    |      *
     *    |   ( \_.="_.="     `--------`     "=._"=._/ )   |      *
     *    |    > _.="                            "=._ <    |      *
     *    |   (_/                                    \_)   |      *
     *    |                                                |      *
     *    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='      *
     *                                                            *
     *                    JUST FIND YOUR BUG !                    *
     **************************************************************
     */

    namespace app\index\model;


    use think\Model;

    class Article extends Model
    {

        /**
         * @return array|mixed
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         * @author: Jackhhy <jackhhy520@qq.com>
         * @name: indexGetArticleToIsRecommend
         * @describe:首页文章推荐
         */
        public function indexGetArticleToIsRecommend(){
            $cacheName=SYSTEM_NAME . 'article_recommend_data_where_recommend';
            $where=['a.delete_time'=>0,'a.is_show'=>1,'a.is_recommend'=>1,'c.delete_time'=>0];

            $data=cache($cacheName); //获取缓存里面的文章

            if($data == false || is_null($data)){
                $field='a.id,a.category_id,a.title,a.description,a.image_url,a.author,a.hits,a.is_recommend,a.comment_num,a.is_top,c.name as category_name,a.url,a.create_time,c.url as category_url';

                $data=$this->alias('a')
                    ->join('category c','a.category_id=c.id')
                    ->where($where)
                    ->field($field)
                    ->order('is_top DESC,create_time DESC')
                    ->limit(10)
                    ->select()
                    ->toArray();

                cache($cacheName,$data,'','article_data'); //存到缓存里面
            }

            return $data;
        }

    }